<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css" />
    <link rel="stylesheet" href="../../lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css" />
    <title>菜单配置</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限管理 <span
        class="c-gray en">&gt;</span> 菜单管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
<div class="pd-30">
    <div></div>
    <div>
        <div class="pos-a" style="width:99%;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5; overflow:auto;">
            <!--<div class="pd-20 ml-5"><a class="btn btn-secondary size-MINI radius" href="##" onclick="selectAll()" >全选</a><a class="btn radius size-MINI ml-10" href="##" onclick="cancelAll()">取消</a></div>-->
            <ul id="treeDemo" class="ztree" style="margin-top: 50px"></ul>
            <div class="text-c pd-20" style="margin-top: 150px; float: left">
                <a class="btn btn-secondary radius" href="##" onclick="showInsertVal()" >新增</a>
                <a class="btn btn-secondary radius" href="##" onclick="showUpdateVal()">修改</a>
                <a class="btn btn-secondary radius" href="##" onclick="deleteMenuVal()">删除</a>

                <div style="margin-top: 20px; display: none" id="savaId">
                    <select class="input-text radius" id="menuLevel">
                        <option value="0">一级菜单</option>
                        <option value="1">选中下级菜单</option>
                    </select>

                    <div style="margin-top: 20px">
                        <span>该菜单页面是否拥有基础按钮&nbsp;&nbsp;&nbsp;</span>
                        <input name="addButtonStatus" type="radio" id="addButtonStatusY" value="1"/>是&nbsp;&nbsp;
                        <input name="addButtonStatus" type="radio" id="addButtonStatusN" checked="checked" value="0"/>否
                    </div>

                    <input class="input-text radius" style="margin-top: 20px" type="text" name="" id="menuName" placeholder="请输入新增菜单名称">
                    <a class="btn btn-secondary radius" href="##" onclick="saveMenu()">确认</a>
                    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                       href="#" title="刷新" onclick="resh()">
                        取消</a>
                    <!--<a class="btn radius ml-10" href="javascript:location.replace(location.href);" onclick="cancel_back()">取消</a>-->
                </div>

                <div style="margin-top: 20px; display: none" id="updateId">
                    <input class="input-text radius" type="text" name="" id="updateMenuName">
                    <div style="margin-top: 5px; margin-top: 10px">
                        <span>该菜单页面是否拥有基础按钮&nbsp;&nbsp;&nbsp;</span>
                        <input name="upButtonStatus" type="radio" id="buttonStatusY" value="1"/>是&nbsp;&nbsp;
                        <input name="upButtonStatus" type="radio" id="buttonStatusN" value="0"/>否
                    </div>
                    <div style="margin-top: 20px">
                        <a class="btn btn-secondary radius" href="##" onclick="upateMenu()">确认</a>
                        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                           href="#" title="刷新" onclick="resh()">
                            取消</a>
                        <!--<a class="btn radius ml-10" href="##" onclick="cancel_back()">取消</a>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/zTree/v3/js/jquery.ztree.all-3.5.min.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/access/configuration-menu.js?rev=@@hash"></script>
<script type="text/javascript">
    function cancel_back() {
        var index =  parent.location.reload();
        parent.layer.close(index);
    }
    function selectAll() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        treeObj.checkAllNodes(true);//全选
    }
    function cancelAll() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        treeObj.checkAllNodes(false);//取消全选
    }
    $(function () {
        sessionStorage.removeItem("menuId");
        sessionStorage.removeItem("menuName");
        sessionStorage.removeItem("buttonStatus");

        $.ajax({
            type: "POST",
            url: root.accessInter.access_menuqxApi,
            cache: false,  //禁用缓存
            dataType: "json",
            data: {
                ROLE_ID: 31
            },
            success: function (result) {
                console.log(result)
                var setting = {
                    view: {
                        dblClickExpand: false,
                        showLine: false,
                        selectedMulti: false
                    },
                    data: {
                        simpleData: {
                            enable:true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: ""
                        }
                    },
                    /*check:{
                        autoCheckTrigger:false,
                        chkboxType:{"Y":"ps","N":"ps"},
                        chkStyle:"checkbox",
                        enable:true,
                        nocheckInherit:false,
                        chkDisabledInherit:false,
                        radioType:"level"
                    },*/
                    callback: {
                        onClick: onClick,
                    }
                };
                function onClick(e, treeDemo, treeNode) {
                    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                    if(treeNode.open == true){
                        treeObj.expandNode(treeNode, false, false, true,true);
                    }else{
                        treeObj.expandNode(treeNode, true, false, true,true);
                    }
                    // 每次存储选中的当前节点保存父级菜单按钮
                    console.log(treeObj.getSelectedNodes()[0]);
                    sessionStorage.setItem("menuId", treeObj.getSelectedNodes()[0].id);
                    sessionStorage.setItem("menuName", treeObj.getSelectedNodes()[0].name);
                    sessionStorage.setItem("buttonStatus", treeObj.getSelectedNodes()[0].buttonStatus);
                    document.getElementById("savaId").style.display = 'none';
                    document.getElementById("updateId").style.display = 'none';
                };

                var zNodes =[];
                for (var i=0;i<result.menuList.length;i++){
                    //第一层i
                    var iName = result.menuList[i];
                    zNodes.push({ id:iName.MENU_ID, pId:iName.PARENT_ID, name: iName.MENU_ID + '|' + iName.MENU_NAME, checked:iName.hasMenu, buttonStatus:iName.BUTTON_STATUS});
                    if(result.menuList[i].subMenu != []){
                        for (var j=0;j<result.menuList[i].subMenu.length;j++){
                            //   第二层j
                            var jName = result.menuList[i].subMenu[j];
                            zNodes.push({ id:jName.MENU_ID, pId:jName.PARENT_ID, name:jName.MENU_ID + '|' + jName.MENU_NAME, checked:jName.hasMenu, buttonStatus:jName.BUTTON_STATUS});
                            if(result.menuList[i].subMenu[j].subMenu != []){
                                for (var k=0;k<result.menuList[i].subMenu[j].subMenu.length;k++){
                                    // 第三层k
                                    var kName = result.menuList[i].subMenu[j].subMenu[k];
                                    zNodes.push({ id:kName.MENU_ID, pId:kName.PARENT_ID, name:kName.MENU_ID +'|' + kName.MENU_NAME, checked:kName.hasMenu, buttonStatus:kName.BUTTON_STATUS});
                                    if(result.menuList[i].subMenu[j].subMenu[k].subMenu !=[]){
                                        for(var m=0;m<result.menuList[i].subMenu[j].subMenu[k].subMenu.length;m++){
                                            //第四层m
                                            var mName = result.menuList[i].subMenu[j].subMenu[k].subMenu[m];
                                            zNodes.push({ id:mName.MENU_ID, pId:mName.PARENT_ID, name:mName.MENU_ID + '|' + mName.MENU_NAME, checked:mName.hasMenu, buttonStatus:mName.BUTTON_STATUS});
                                            if(result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu !=[]){
                                                for(var n=0;n<result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu.length;n++){
                                                    //第五层n
                                                    var nName = result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n];
                                                    zNodes.push({ id:nName.MENU_ID, pId:nName.PARENT_ID, name:nName.MENU_ID+ "|" + nName.MENU_NAME, checked:nName.hasMenu, buttonStatus:nName.BUTTON_STATUS});
                                                    if (result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu != []){
                                                        for(var p=0;p<result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu.length;p++){
                                                            //第六层
                                                            var pName = result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu[p];
                                                            zNodes.push({ id:pName.MENU_ID, pId:pName.PARENT_ID, name:pName.MENU_ID+ "|" + pName.MENU_NAME, checked:pName.hasMenu, buttonStatus:pName.BUTTON_STATUS});
                                                            if (result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu[p].subMenu != []){
                                                                for(var q=0;q<result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu[p].subMenu.length;q++){
                                                                    //第七层
                                                                    var qName = result.menuList[i].subMenu[j].subMenu[k].subMenu[m].subMenu[n].subMenu[p].subMenu[q];
                                                                    zNodes.push({ id:qName.MENU_ID, pId:qName.PARENT_ID, name:qName.MENU_ID+ "|" + qName.MENU_NAME, checked:qName.hasMenu, buttonStatus:qName.BUTTON_STATUS});
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $(document).ready(function(){
                    var t = $("#treeDemo");
                    t = $.fn.zTree.init(t, setting, zNodes);
                    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                    treeObj.expandAll(false);
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    });

</script>
</body>
</html>